#!/usr/bin/bash

list+="while "
list+="for "
list+="int "
list+="float "
list+="struct "
list+="char "
list+="union "
list+="main "
list+="void "
list+="do "
list+="return "

while true
do
    read -p "请输入要检测的变量名:" var

    # 判定是否以数字开头
    v1=`echo $var | sed 's/^[0-9]//'`
    if [ $v1 != $var ]; then
        echo "不合格！"
        continue
    fi

    # 判定是否包含非法字符（仅包含大小大小写和数字、下划线）
    v2=`echo $var | sed 's/[a-zA-Z0-9_]*//'`
    if [ ! -z $v2 ]; then
        echo "不合格"
        continue
    fi

    # 判定是否跟关键冲突
    flag=1
    for key_word in $list
    do
        echo "$key_word"
        if [ $var == $key_word ]; then
            echo "不合格"
            flag=0
            break
        fi
    done

    if [ $flag -eq 1 ]; then
        echo "合格"
    fi

done
